package com.sqsf.javabean;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "UserServlet", value = "/user")
public class UserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //从spring容器中获取对象 并输出
        ServletContext servletContext = request.getServletContext();
        ClassPathXmlApplicationContext applicationContext= (ClassPathXmlApplicationContext) servletContext.getAttribute("spring");
        //从spring容器中取出指定的对象
        User bean = applicationContext.getBean(User.class);
        System.out.println(bean);
    }
}
